package com.iceframework.core.utils;

import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.net.URL;

public class DownloadResourceUtils {

	public static void downloadResourceFromUrl(String urlList, String path) throws Exception {
		URL url = null;
		url = new URL(urlList);
		DataInputStream dataInputStream = new DataInputStream(url.openStream());

		FileOutputStream fileOutputStream = new FileOutputStream(new File(path));
		ByteArrayOutputStream output = new ByteArrayOutputStream();

		byte[] buffer = new byte[2048];
		int length;

		while ((length = dataInputStream.read(buffer)) > 0) {
			output.write(buffer, 0, length);
		}
		fileOutputStream.write(output.toByteArray());
		output.close();
		fileOutputStream.close();
		dataInputStream.close();
	}

}